package com.szzg10.pattern.iterator;

import java.util.Iterator;

public class StringArrayIterator implements Iterator<String> {

	private String[] items;
	private int position;
	
	public StringArrayIterator(String[] items) {
		this.items = items;
		position = 0;
	}
	
	@Override
	public boolean hasNext() {
		if(position < items.length && items[position ] != null) {
			return true;
		}
		return false;
	}

	@Override
	public String next() {
		return items[position++];
	}

	@Override
	public void remove() {
		for(int i = position; i < items.length - 1; i++) {
			items[i] = items[i + 1];
		}
		
		items[items.length - 1] = null;
	}

}
